package cn.tedu.medicalmanagementsystem.base.response;

import cn.tedu.medicalmanagementsystem.escort.pojo.entity.EscortAppointment;
import cn.tedu.medicalmanagementsystem.escort.pojo.vo.EscortVO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult<T> {
    private Integer state;
    private String message;
    private T data;

    public JsonResult(StatusCode statusCode) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    public JsonResult(StatusCode statusCode, T data) {
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public static <T> JsonResult<T> ok(T data) {
        return new JsonResult<>(StatusCode.OPERATION_SUCCESS, data);
    }

    public static <T> JsonResult<T> ok() {
        return ok(null);
    }

    public static <T> JsonResult<T> ok(String message) {
        JsonResult<T> result = new JsonResult<>(StatusCode.OPERATION_SUCCESS);
        result.setMessage(message);
        return result;
    }

    public static <T> JsonResult<T> fail(int code, String message) {
        JsonResult<T> result = new JsonResult<>();
        result.setState(code);
        result.setMessage(message);
        return result;
    }
    public static JsonResult fail(String 未找到对应服务) {
        return new JsonResult(StatusCode.OPERATION_FAIL, 未找到对应服务);
    }

    public static JsonResult fail(StatusCode statusCode, String message) {
        return new JsonResult();
    }

    public static <T> JsonResult<T> success() {
        return success(null);
    }

    public static <T> JsonResult<T> success(T data) {
        JsonResult<T> result = new JsonResult<>();
        result.setState(StatusCode.OPERATION_SUCCESS.getState());
        result.setMessage(StatusCode.OPERATION_SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> JsonResult<T> fail(StatusCode statusCode) {
        JsonResult<T> result = new JsonResult<>();
        result.setState(statusCode.getState());
        result.setMessage(statusCode.getMessage());
        return result;
    }

    public static JsonResult<Object> ok(String 获取成功, List<EscortAppointment> appointments) {
        return null;
    }

    // 构造函数、getter 和 setter 方法

    public static <T> JsonResult<T> ok(String message, T data) {
        JsonResult<T> result = new JsonResult<>();
        result.setState(2000); // 成功状态码
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> JsonResult<T> error(String message) {
        JsonResult<T> result = new JsonResult<>();
        result.setState(5000); // 失败状态码
        result.setMessage(message);
        return result;
    }
    @Override
    public String toString() {
        return "JsonResult{" +
                "state=" + state +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
